<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>参与投票</title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
</head>
<body>

<div id="app">
	<common>
		<div id="vote" class="wrap">
			<h2>参与投票</h2>
			<ul class="list">
				<li>
					<h4>{{vote.vname}}</h4>
					<p class="info">共有 {{vote.icnt}} 个选项，已有 {{vote.ucnt}} 个网友参与了投票。</p>
					<form method="post" action="Vote!save.action">
						<input type="hidden" name="entityId" value="103"/>
						<ol>
							<li v-for="i in vote.items">
								<input :type="i.vtype=='单选'?'radio':'checkbox'"
									   v-model="iids" name="options" :value="i.id"/>{{i.iname}}
							</li>
						</ol>
						<p class="voteView">
							<input @click.prevent="commit" type="image" src="images/button_vote.gif" />
							<a :href="'view.html'+location.search"><img src="images/button_view.gif" /></a></p>
					</form>
				</li>
			</ul>
		</div>
	</common>
</div>
<script src="js/vue.min.js"></script>
<script src="js/axios.min.js"></script>
<script src="js/vote.js"></script>
<script>
	var v = new Vue({
		el : "#app",
		data:{
			vote: {},
			iids: []
		},
		created(){
			let id = location.search.substring(1);   // ?1
			let url = "demovote/vote/find?id=" + id;
			axios.get(url).then(res=>this.vote = res.data);
		},
		methods:{
			commit(){
				let vid = location.search.substring(1);   // ?1
				let p = new URLSearchParams();
				p.append("vid",vid);
				this.iids.forEach(iid=>p.append("iid", iid));
				axios.post("/demovote/vote/commit",p).then(res=>{
					if(res.data.code == 1){
						location.href = "/view.html?" + vid;
					} else {
						alert(res.data.msg);
					}
				})
			}
		}
	})
</script>

</body>
</html>
